home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Periodicals / CSMP / C.S.M.P. Digest, Issue 3.025 < prev    next >
Internet Message Format  |  1994-06-09  |  47KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: csmp-digest-v3-025, resend
  3. Date: Tue, 10 May 94 17:15:09 MET DST
  4.  
  5.  
  6. Hi,
  7. Issue 25 of the digest contains some binhexed files, which reportedly
  8. caused some dumb mailers to extract the binhex codes and delete the rest.
  9. I have removed the faulty thread; here is a "clean" digest.
  10.  
  11. Francois
  12. pottier@dmi.ens.fr
  13.  
  14. ------
  15.  
  16. C.S.M.P. Digest             Tue, 10 May 94       Volume 3 : Issue 25
  17.  
  18. Today's Topics:
  19.  
  20.         CodeWarrior GOLD DR-2 - Can't seem to generate fast FP code
  21.         Determining if user is on a network
  22.         Sample Think C AE Code
  23.         drawing arrowheads
  24.         writing an INIT... a few questions
  25.  
  26.  
  27.  
  28. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  29. (pottier@clipper.ens.fr).
  30.  
  31. The digest is a collection of article threads from the internet newsgroup
  32. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  33. regularly and want an archive of the discussions.  If you don't know what a
  34. newsgroup is, you probably don't have access to it.  Ask your systems
  35. administrator(s) for details.  If you don't have access to news, you may
  36. still be able to post messages to the group by using a mail server like
  37. anon.penet.fi (mail help@anon.penet.fi for more information).
  38.  
  39. Each issue of the digest contains one or more sets of articles (called
  40. threads), with each set corresponding to a 'discussion' of a particular
  41. subject.  The articles are not edited; all articles included in this digest
  42. are in their original posted form (as received by our news server at
  43. nef.ens.fr).  Article threads are not added to the digest until the last
  44. article added to the thread is at least two weeks old (this is to ensure that
  45. the thread is dead before adding it to the digest).  Article threads that
  46. consist of only one message are generally not included in the digest.
  47.  
  48. The digest is officially distributed by two means, by email and ftp.
  49.  
  50. If you want to receive the digest by mail, send email to listserv@ens.fr
  51. with no subject and one of the following commands as body:
  52.     help                        Sends you a summary of commands
  53.     subscribe csmp-digest Your Name    Adds you to the mailing list
  54.     signoff csmp-digest            Removes you from the list
  55. Once you have subscribed, you will automatically receive each new
  56. issue as it is created.
  57.  
  58. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  59. Questions related to the ftp site should be directed to
  60. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  61. digest are available there.
  62.  
  63. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  64.  
  65.  
  66. -------------------------------------------------------
  67.  
  68. >From bcorrie@csr.UVic.CA (Brian  Corrie)
  69. Subject: CodeWarrior GOLD DR-2 - Can't seem to generate fast FP code
  70. Date: 15 Apr 94 20:51:55 GMT
  71. Organization: University of Victoria
  72.  
  73. G'day,
  74.  
  75. I just recently got my CodeWarrior Gold. I wrote a simple application that
  76. does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  77. to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  78. 10 at work. Timings below:
  79.  
  80. RS6000         2.4 seconds
  81. SPARC10     4.8 seconds
  82. Quadra840AV    40 seconds
  83. PowerMac 6100    53 seconds???????
  84.  
  85. Now obviously this code is running in emulation mode (at least I hope so
  86. or I will be a bit bummed out 8-). The weird thing is that I CAN NOT get
  87. this to change. I am running the PPC version of the compiler, I set the
  88. preferences to what I think they should be to generate native PowerPC code,
  89. use what I think are the right libraries, and lo and behold, it runs slow.
  90.  
  91. Now I am probably missing something obvious, and you are probably saying
  92. RTFM, but really, I have spent the last two days trying to figure this out!
  93. Reading the manual, talking to someone who has a bit more Mac expereince
  94. than I do, etc. Still no luck. What am I doing wrong???? Any ideas?
  95. Is there something obvious that I have to do. Did I install things
  96. incorrectly? Is there a special library I need to use to take advantage
  97. of the PPC floating point hardware? ARGGGHHHH. I want to say "look how
  98. fast my machine is" but I can't at the moment!!!!!
  99.  
  100. Any and all pointers, even those exposing my stupidity, are welcome.
  101.  
  102. Cheers,
  103.  
  104.     Brian
  105.  
  106.  
  107. --
  108.                   Brian Corrie (bcorrie@csr.uvic.ca)
  109. Under the most rigorously controlled conditions of pressure, temperature,
  110. volume, humidity and other variables, the organism will do as it damn well
  111. pleases. Sounds like some of the code I have written......  8-)
  112.  
  113. +++++++++++++++++++++++++++
  114.  
  115. >From usenet@lowry.eche.ualberta.ca (Brian Lowry)
  116. Date: 15 Apr 1994 22:12:20 GMT
  117. Organization: Chem Eng - Univ of Alberta
  118.  
  119. In article <bcorrie.766443115@tara>, bcorrie@csr.UVic.CA (Brian  Corrie)
  120. wrote:
  121.  
  122. > I just recently got my CodeWarrior Gold. I wrote a simple application that
  123. > does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  124. > to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  125. > 10 at work. Timings below:
  126. > RS6000         2.4 seconds
  127. > SPARC10     4.8 seconds
  128. > Quadra840AV    40 seconds
  129. > PowerMac 6100    53 seconds???????
  130.  
  131.   Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  132. speed did you expect?  Obviously you're calling SANE routines while the IBM
  133. is calling efficent PPC routines.  You'd probably see a speed improvement
  134. with even relatively inefficient sin/cos/sqrt algorithms.
  135.  
  136. -- 
  137.  
  138. Brian Lowry
  139.  
  140. +++++++++++++++++++++++++++
  141.  
  142. >From bcorrie@csr.UVic.CA (Brian  Corrie)
  143. Date: 16 Apr 94 00:20:22 GMT
  144. Organization: University of Victoria
  145.  
  146. usenet@lowry.eche.ualberta.ca (Brian Lowry) writes:
  147. >In article <bcorrie.766443115@tara>, bcorrie@csr.UVic.CA (Brian  Corrie)
  148. >wrote:
  149.  
  150. >> I just recently got my CodeWarrior Gold. I wrote a simple application that
  151. >> does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  152. >> to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  153. >> 10 at work. Timings below:
  154. >> 
  155. >> RS6000         2.4 seconds
  156. >> SPARC10     4.8 seconds
  157. >> Quadra840AV    40 seconds
  158. >> PowerMac 6100    53 seconds???????
  159.  
  160. >  Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  161. >speed did you expect?  Obviously you're calling SANE routines while the IBM
  162. >is calling efficent PPC routines.  You'd probably see a speed improvement
  163. >with even relatively inefficient sin/cos/sqrt algorithms.
  164.  
  165. Care to elaborate a bit on that? Like I said, I am not a Mac programmer
  166. and don't know a lot about SANE, but it doesn't make much sense that
  167. my PowerMac is SLOWER than a Quadra840 when the code on the PowerMac
  168. is native PowerPC code. Surely the sin and cos functions are implemented
  169. using the native PowerPC code and isn't being implemented as emmulated
  170. 020 code!?!?!?
  171.  
  172. How does one expect to take advantage of the floating point speed of the
  173. PowerPC architecture if basic mathematical functions like sin, cos, and
  174. sqrt are not implemented natively. Seems rather silly to me. Am I out to
  175. lunch on this one???? Is their not a native implementation of SANE? I was
  176. expecting to get an execution time of below ten seconds based on what I
  177. have read about the PowerPC specs.
  178.  
  179. Any insights. Can someone set me straight, this doesn't make sense to me.
  180.  
  181.     Brian (stressed about his slow PowerMac) Corrie
  182.  
  183.  
  184.  
  185.     Brian
  186.  
  187. --
  188.                   Brian Corrie (bcorrie@csr.uvic.ca)
  189. Under the most rigorously controlled conditions of pressure, temperature,
  190. volume, humidity and other variables, the organism will do as it damn well
  191. pleases. Sounds like some of the code I have written......  8-)
  192.  
  193. +++++++++++++++++++++++++++
  194.  
  195. >From bcorrie@csr.UVic.CA (Brian  Corrie)
  196. Date: 16 Apr 94 01:18:07 GMT
  197. Organization: University of Victoria
  198.  
  199. Dave Falkenburg <falken@apple.com> writes:
  200. >In article <usenet-150494160853@lowry.eche.ualberta.ca> Brian Lowry,
  201. >usenet@lowry.eche.ualberta.ca writes:
  202. Brian Corrie originally wrote:
  203. >>> I just recently got my CodeWarrior Gold. I wrote a simple application that
  204. >>> does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  205. >>> to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  206. >>> 10 at work. Timings below:
  207. >>> 
  208. >>> RS6000         2.4 seconds
  209. >>> SPARC10     4.8 seconds
  210. >>> Quadra840AV    40 seconds
  211. >>> PowerMac 6100    53 seconds???????
  212. >>
  213. >>  Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  214. >>speed did you expect?  Obviously you're calling SANE routines while the IBM
  215. >>is calling efficent PPC routines.  You'd probably see a speed improvement
  216. >>with even relatively inefficient sin/cos/sqrt algorithms.
  217. >>
  218. >>-- 
  219. >>
  220. >>Brian Lowry
  221.  
  222. >Remember that MW DR/2 doesn't generate really optimal code (yet). You're not
  223. >calling SANE, you are just executing non-optimzied code on a RISC machine.
  224.  
  225. I realize that the code optimization isn't the best, but surely running 
  226. native code on a PowerPC should run faster than a Quadra840 with a
  227. 68881?2.  If not, I want my money back!!!! Seriously, if the sin, cos,
  228. sqrt are running as native code and not being emulated as 020 through
  229. SANE or some such bizarre twist, then why can't the PowerPC beat a
  230. Quadra 840. Even if I turn off optimization and turn on debugging
  231. and profiling on the SPARC10 I get a run time of 7.9 seconds. Still a
  232. ton and a half less than 53. We are talking an order of magnitude
  233. difference when I would expect them to be in the same ball park.
  234.  
  235. Almost all 3D graphics use sin, cos, and sqrt extensively. How can all
  236. those native 3D programs claim massive speedups over high end Quadras
  237. when I am getting worse performance!?! It just don't make sense mon,
  238. I am still convinced that I am doing something ridiculously stoopid.
  239. Please, someone just tell me what it is!  8-)
  240.  
  241. >If you compile on AIX with "-lm" and ship the code back over to your PowerMac
  242. >you should see VERY nice performance improvements.
  243.  
  244. >Also: Were you using the Apple mathlib?
  245.  
  246. I was using the MathLib that comes with the CW DR/2 release, whatever
  247. that is. It seems to me that I must be using the wrong library, but
  248. its beyond me which one I should be using.... 
  249.  
  250. I will play some more with the compiler tonight and report further on
  251. this "drama"
  252.  
  253. Cheers,
  254.  
  255.     Brian
  256.  
  257. --
  258.                   Brian Corrie (bcorrie@csr.uvic.ca)
  259. Under the most rigorously controlled conditions of pressure, temperature,
  260. volume, humidity and other variables, the organism will do as it damn well
  261. pleases. Sounds like some of the code I have written......  8-)
  262.  
  263. +++++++++++++++++++++++++++
  264.  
  265. >From Chuck Browne <chuck@molecule.physics.drexel.edu>
  266. Date: Sat, 16 Apr 1994 02:37:14 GMT
  267. Organization: Drexel Univ. Physics
  268.  
  269. In article <usenet-150494160853@lowry.eche.ualberta.ca> Brian Lowry,
  270. usenet@lowry.eche.ualberta.ca writes:
  271. >  Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  272. >speed did you expect?  Obviously you're calling SANE routines while the
  273. IBM
  274. >is calling efficent PPC routines.  You'd probably see a speed improvement
  275. >with even relatively inefficient sin/cos/sqrt algorithms.
  276.  
  277. Well, in the MW manual, it says about SANE for the PowerMacs:
  278.  
  279. "SANE is dead." 
  280.  
  281. Are you using the math library with <fp.h>? I believe that is what you
  282. should be using. Not that I would really know, as I don't have a PowerMac
  283. (although I will be able to test some calcs next week on one), but 
  284. since when has not knowing what you're talking about been a crime on 
  285. usenet? :-)
  286.  
  287. Anyway, I don't know if you're using the ANSI libs. They're probably 
  288. slower than the math library...
  289.  
  290. Chuck
  291.  
  292. +++++++++++++++++++++++++++
  293.  
  294. >From Dave Falkenburg <falken@apple.com>
  295. Date: Fri, 15 Apr 1994 23:58:13 GMT
  296. Organization: Apple Computer, Inc.
  297.  
  298. In article <usenet-150494160853@lowry.eche.ualberta.ca> Brian Lowry,
  299. usenet@lowry.eche.ualberta.ca writes:
  300. >> I just recently got my CodeWarrior Gold. I wrote a simple application
  301. that
  302. >> does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  303. >> to test the speed of my PowerMac 6100/60 compared to an RS6000 and
  304. SPARC
  305. >> 10 at work. Timings below:
  306. >> 
  307. >> RS6000         2.4 seconds
  308. >> SPARC10     4.8 seconds
  309. >> Quadra840AV    40 seconds
  310. >> PowerMac 6100    53 seconds???????
  311. >
  312. >  Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  313. >speed did you expect?  Obviously you're calling SANE routines while the
  314. IBM
  315. >is calling efficent PPC routines.  You'd probably see a speed improvement
  316. >with even relatively inefficient sin/cos/sqrt algorithms.
  317. >
  318. >-- 
  319. >
  320. >Brian Lowry
  321.  
  322. Remember that MW DR/2 doesn't generate really optimal code (yet). You're
  323. not
  324. calling SANE, you are just executing non-optimzied code on a RISC machine.
  325.  
  326. If you compile on AIX with "-lm" and ship the code back over to your
  327. PowerMac
  328. you should see VERY nice performance improvements.
  329.  
  330. Also: Were you using the Apple mathlib?
  331.  
  332. -Dave Falkenburg
  333. -Apple Computer, Inc.
  334.  
  335. +++++++++++++++++++++++++++
  336.  
  337. >From rang@winternet.mpls.mn.us (Anton Rang)
  338. Date: 16 Apr 1994 01:56:31 GMT
  339. Organization: Minnesota Angsters
  340.  
  341. In article <bcorrie.766443115@tara> bcorrie@csr.UVic.CA (Brian  Corrie) writes:
  342. >I just recently got my CodeWarrior Gold. I wrote a simple application that
  343. >does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  344. >to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  345. >10 at work. Timings below:
  346.  
  347.   Aha!  You have discovered Apple's Incredibly Inefficient Trig
  348. Functions.  They're so bad that, as you discovered, the 840AV is
  349. faster.  The cure is to write your own, snarf the library from the
  350. RS/6000 (probably legal issues involved), or curse Apple until they
  351. fix it.  (Hmm.)
  352.  
  353.   Check the timing of add/multiply and you'll see it's way faster than
  354. any 68000.  So if Apple even used the same algorithms that the 68882
  355. uses (or heck, even SANE) it would be faster.  :(
  356. --
  357. Anton Rang (rang@winternet.mpls.mn.us)
  358.  
  359. +++++++++++++++++++++++++++
  360.  
  361. >From johnmce@world.std.com (John McEnerney)
  362. Date: Sat, 16 Apr 1994 07:16:19 GMT
  363. Organization: The World Public Access UNIX, Brookline, MA
  364.  
  365. usenet@lowry.eche.ualberta.ca (Brian Lowry) writes:
  366.  
  367. >In article <bcorrie.766443115@tara>, bcorrie@csr.UVic.CA (Brian  Corrie)
  368. >wrote:
  369.  
  370. >> I just recently got my CodeWarrior Gold. I wrote a simple application that
  371. >> does a bunch of floating point calculations (sin, cos, sqrt, *, / etc.)
  372. >> to test the speed of my PowerMac 6100/60 compared to an RS6000 and SPARC
  373. >> 10 at work. Timings below:
  374. >> 
  375. >> RS6000         2.4 seconds
  376. >> SPARC10     4.8 seconds
  377. >> Quadra840AV    40 seconds
  378. >> PowerMac 6100    53 seconds???????
  379.  
  380. >  Since sin, cos, and sqrt aren't supported by the PPC601, what sort of
  381. >speed did you expect?  Obviously you're calling SANE routines while the IBM
  382. >is calling efficent PPC routines.  You'd probably see a speed improvement
  383. >with even relatively inefficient sin/cos/sqrt algorithms.
  384.  
  385. This should not be true. When using sin(), cos() etc. one normally links 
  386. against the MathLib shared library from Apple. These routines were 
  387. supposedly coded for high performance.
  388.  
  389. -- John McEnerney, Metrowerks PowerPC Product Architect
  390.  
  391.  
  392. +++++++++++++++++++++++++++
  393.  
  394. >From jwbaxter@olympus.net (John W. Baxter)
  395. Date: Fri, 15 Apr 1994 20:36:24 -0700
  396. Organization: Internet for the Olympic Peninsula
  397.  
  398. In article <bcorrie.766459087@tara>, bcorrie@csr.UVic.CA (Brian  Corrie)
  399. wrote:
  400.  
  401. > I was using the MathLib that comes with the CW DR/2 release, whatever
  402. > that is. It seems to me that I must be using the wrong library, but
  403. > its beyond me which one I should be using.... 
  404.  
  405. That should be the right one (and should actually mean that you're running
  406. the ROM-based fragment).
  407.  
  408. What data type are you using for your floating point?  float and double are
  409. good (supported, except for some operations, by the chip)...long double is
  410. not (done in software).  If you are using long double (and even more if you
  411. are using one of the extended types left over from the old days), I'd
  412. suggest you switch to double_t.  When compiled for PPC, that gives you
  413. double (64-bit); when compiled for 68K Mac, it gives you long double (80 or
  414. 96 bit depending upon FPU setting).  On PPC compiles, long double is the
  415. [somewhat strange] 128-bit format.
  416.  
  417. -- 
  418. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  419.    jwbaxter@pt.olympus.net
  420.  
  421. +++++++++++++++++++++++++++
  422.  
  423. >From somogyi@macuser.ziff.com (Stephan Somogyi)
  424. Date: Sat, 16 Apr 1994 17:24:31 GMT
  425. Organization: MacUser Magazine US
  426.  
  427. In article <CoCC78.D3r@world.std.com>, johnmce@world.std.com (John
  428. McEnerney) wrote:
  429.  
  430. > When using sin(), cos() etc. one normally links  against the MathLib
  431. > shared library from Apple. These routines were  supposedly coded for
  432. > high performance.
  433.  
  434. A fellow from Apple said in the PowerPC Talk area on AppleLink that they
  435. are aware of MathLib's bad trig performance and are working on resolving
  436. the problem. For the time being, the prudent thing to do seems to be to
  437. get another trig implementation.
  438.  
  439. __________________________________________________________________________
  440. Stephan Somogyi                 "Davidian Inside"                  MacUser
  441.  
  442. +++++++++++++++++++++++++++
  443.  
  444. >From squeegee@world.std.com (Stephen C. Gilardi)
  445. Date: Sat, 16 Apr 1994 20:20:08 GMT
  446. Organization: SQ Software via The World Public Access UNIX, Brookline, MA
  447.  
  448. oliver@psy.fsu.edu (Bill Oliver) writes:
  449.  
  450. >I've also been looking at the floating point performance of CodeWarrior
  451. >C code on my Centris 660AV Mac. I've compiled a test program using the
  452. >various ANSI881 libraries with what I believe are the appropriate
  453. >compiler options. The program takes *twice* as long to exectute than
  454. >the same program compiled on a NeXT Cube, which has the same CPU (25MHz
  455. >68040).Obviously, I must be doing something wrong. Are there any
  456. >example programs available (with projects) that illustrate how to get
  457. >fast FP code from CW?
  458.  
  459. If you just include math.h, then all trig functions, logs, etc. will
  460. be calculated using SANE.  If you #define __FASTMATH__ and/or
  461. __HYBRIDMATH__ before include math.h, then the 68881 will be used
  462. directly for those functions (at the expense of the extra error
  463. checking and control which you get with SANE).
  464.  
  465. However, I believe there is a bug in the DR/2 math.h which makes those
  466. #defines not have the desired effect.
  467.  
  468. Here's a portion of the bug report I sent:
  469.  
  470. [I think math.h is wrong...]
  471.  
  472. Here's how I think the relevant portion of math.h should read:
  473.  
  474. #ifdef __FASTMATH__
  475. #define log(x)        _log(x)
  476. #define log10(x)    _log10(x)
  477. #endif
  478.  
  479. #ifdef    __HYBRIDMATH__
  480. #define sin(x)        _sin(x)
  481. #define cos(x)        _cos(x)
  482. #define tan(x)        _tan(x)
  483. #define asin(x)        _asin(x)
  484. #define acos(x)        _acos(x)
  485. #define atan(x)        _atan(x)
  486. #define sinh(x)        _sinh(x)
  487. #define cosh(x)        _cosh(x)
  488. #define tanh(x)        _tanh(x)
  489. #define exp(x)        _exp(x)
  490. #define sqrt(x)        _sqrt(x)
  491. #define fabs(x)        _fabs(x)
  492. #define fmod(x,y)    _fmod((x),(y))
  493. #define ldexp(x,n)    _ldexp((x),(n))
  494. #endif
  495.  
  496. I believe that the underscores indicate direct calls to the 68881.
  497. With it defined as I suggest, the MATH macros work as documented.
  498.  
  499. --Steve
  500.  
  501. +++++++++++++++++++++++++++
  502.  
  503. >From rang@winternet.mpls.mn.us (Anton Rang)
  504. Date: 17 Apr 1994 02:39:15 GMT
  505. Organization: Minnesota Angsters
  506.  
  507. In article <CoCC78.D3r@world.std.com> johnmce@world.std.com (John McEnerney) writes:
  508. >This should not be true. When using sin(), cos() etc. one normally links 
  509. >against the MathLib shared library from Apple. These routines were 
  510. >supposedly coded for high performance.
  511.  
  512.   Hmm.  Well, they ought to be, but another poster earlier (on
  513. c.s.powerpc) gave me a benchmark to run on the 8100/80, and it
  514. indicated that sin/cos are *very* slow compared to almost any other
  515. implementation.  A few selected rows from the table he sent --
  516.  
  517. Machine                    MFLOPS        FLOPS/sin()
  518. - -----                    ------        -----------
  519.  
  520. Cray-2                                   45.06             18.43
  521. PowerMac 8100/80 (Apple SDK beta)        37.50            1223.88
  522. IBM RS6000/550                 22.22              25.89
  523. PowerMac 8100/80 (Metrowerks 1.0a1)      14.28             464.98
  524. IBM RS6000/320H                     13.51              28.15
  525.  
  526. The MFLOPS is calculated in a tight loop where the multiply-add can be
  527. used to advantage, thus the relatively high performance.  The compiler
  528. makes a considerable difference here due primarily to loop unrolling,
  529. which allows better instruction scheduling, and the use of the
  530. load-with-update instructions by the Apple SDK compiler.
  531.  
  532. FLOPS/sin() is the relative performance of a loop which calls sin()
  533. instead of doing multiplication/addition.  Note the incredibly slow
  534. performance....
  535. --
  536. Anton Rang (rang@winternet.mpls.mn.us)
  537.  
  538. +++++++++++++++++++++++++++
  539.  
  540. >From Dave Falkenburg <falken@apple.com>
  541. Date: Mon, 18 Apr 1994 21:08:56 GMT
  542. Organization: Apple Computer, Inc.
  543.  
  544. In article <CoCC78.D3r@world.std.com> John McEnerney,
  545. johnmce@world.std.com writes:
  546. >This should not be true. When using sin(), cos() etc. one normally links 
  547. >against the MathLib shared library from Apple. These routines were 
  548. >supposedly coded for high performance.
  549. >
  550. >-- John McEnerney, Metrowerks PowerPC Product Architect
  551.  
  552. My bet is that they are coded to be highly accurate, so that when someone
  553. decides to build a bridge or an airplane using a Mac it won't fail due to
  554. a rounding error.
  555.  
  556. Lawyers are great, aren't they?
  557.  
  558. BTW: One of the NuCalc guys typed up a REALLY fast version of mathlib
  559. that is less accurate, but MUCH faster. Think about table lookup and
  560. interpolation. He probably wouldn't want you to design his next car with
  561. it, however.
  562.  
  563. -Dave Falkenburg
  564. -Apple Computer, Inc.
  565.  
  566. +++++++++++++++++++++++++++
  567.  
  568. >From bcorrie@csr.UVic.CA (Brian  Corrie)
  569. Date: 20 Apr 94 20:39:44 GMT
  570. Organization: University of Victoria
  571.  
  572. ViviStar@ACM.org (Jonathan Hess) writes:
  573. >In article <bcorrie.766459087@tara>
  574. >bcorrie@csr.UVic.CA (Brian  Corrie) writes:
  575.  
  576. >> Almost all 3D graphics use sin, cos, and sqrt extensively. How can all
  577. >> those native 3D programs claim massive speedups over high end Quadras
  578. >> when I am getting worse performance!?! It just don't make sense mon,
  579. >> I am still convinced that I am doing something ridiculously stoopid.
  580. >> Please, someone just tell me what it is!  8-)
  581.  
  582. >While it is besides the point of this thread I would tend to disagree
  583. >with the statement that "almost all 3D graphics use sin, cos, and sqrt
  584. >extensively."  Successfully fast packages avoid sin, cos, and sqrt as
  585. >much as possibly.  You can rewrite the basic tranform and projection
  586. >equations to where the 1 required trig operation can be computed and
  587. >stored in a constant once per projection.
  588.  
  589. Hmm, I guess my previous post demonstrates that my
  590. fingers do fly faster than my brain (which implies my brain ain't
  591. to fast because I can't type!!! 8-). On thinking about it, I agree,
  592. sin and cos are not used very often in graphics code. I was thinking
  593. of shading calculations that can use trig functions, but on reflection
  594. they rarely use sin/cos as there are usually more efficient ways
  595. of doing the computation (on reflection, shading...hmmm, a bit of a pun...!)
  596.  
  597. >Ray tracers are another story since they have to do a lot more
  598. >calculations with angles of incidence and things.
  599.  
  600. Even ray tracers can get away with using dot product, cross product etc.
  601. and rarely use sin/cos. It is just convenient to think of them as sin/cos
  602. as I did above.
  603.  
  604. Anyway, back to the thread of hacking down the slow sin/cos routines on
  605. the PowerMacs. I still say that it is ridiculous for a Quadra 840 to
  606. be faster than a PowerMac on native floating point sin/cos calculations.
  607. Still no insights as to what I am doing wrong, if anything. Are sin/cos
  608. really that slow on the PowerMacs???
  609.  
  610. Cheers,
  611.  
  612.     Brian
  613.  
  614.  
  615. --
  616.                   Brian Corrie (bcorrie@csr.uvic.ca)
  617. Under the most rigorously controlled conditions of pressure, temperature,
  618. volume, humidity and other variables, the organism will do as it damn well
  619. pleases. Sounds like some of the code I have written......  8-)
  620. >From eric.larson@f620.n2605.z1.fidonet.org (eric larson)
  621. Subject: CodeWarrior GOLD DR-2 - Can't seem to generate fast FP code
  622. Date: 20 Apr 94 18:52:00 -0500
  623. Organization: FidoNet:* File Edit View Label Special                 ? D (1:2605/620)
  624.  
  625.  > In article <CoCC78.D3r@world.std.com> John McEnerney,
  626.  
  627.  >>This should not be true. When using sin(), cos() etc. one normally links
  628.  >>against the MathLib shared library from Apple. These routines were
  629.  >>supposedly coded for high performance.
  630.  
  631.  > My bet is that they are coded to be highly accurate, so that when
  632.  > someone decides to build a bridge or an airplane using a Mac it won't
  633.  > fail due to a rounding error.
  634.  
  635. Butbutbut why would Seymour Cray ship a machine that produces lousy floating
  636. point results? These things are generally used for simulations far more heavily
  637. than an Mac ever is.
  638.  
  639. Meethinks this should be investigated carefully.
  640.  
  641. +++++++++++++++++++++++++++
  642.  
  643. >From rmcassid@uci.edu (Robert Cassidy)
  644. Date: Thu, 21 Apr 1994 12:41:21 -0800
  645. Organization: TLG Project
  646.  
  647. In article <bcorrie.766874384@tara>, bcorrie@csr.UVic.CA (Brian  Corrie)
  648. wrote:
  649.  
  650. [stuff deleted]
  651.  
  652. > Even ray tracers can get away with using dot product, cross product etc.
  653. > and rarely use sin/cos. It is just convenient to think of them as sin/cos
  654. > as I did above.
  655. > Anyway, back to the thread of hacking down the slow sin/cos routines on
  656. > the PowerMacs. I still say that it is ridiculous for a Quadra 840 to
  657. > be faster than a PowerMac on native floating point sin/cos calculations.
  658. > Still no insights as to what I am doing wrong, if anything. Are sin/cos
  659. > really that slow on the PowerMacs???
  660.  
  661. Since sometimes you *have* to do a lot of sin/cos work I don't think these
  662. functions should be ignored. I'm toying with the idea of writing a fp
  663. library (probably mostly trig) that would calculate w.r.t. a determined
  664. precision. I remember writing programs on the VAX at school that seemed
  665. unbelievably slow at sin/cos. It turned out that I was getting far more
  666. precision than I needed. I rewrote the routines and got something like a
  667. 10x speed improvement. Often you don't need a lot of precision
  668. (particularly with graphics) so why do all of the work of calculating what
  669. you don't use? If there is interest in this I may pursue it further (of
  670. course I have to get a PM first! :-)
  671.  
  672. -- 
  673. Robert Cassidy
  674. TLG Project
  675. UC Irvine
  676.  
  677. Let's hope 'Information SuperTollroad' isn't the catchphrase of the next
  678. decade...
  679.  
  680. +++++++++++++++++++++++++++
  681.  
  682. >From AppleGG@lamg.com (Gordon Apple)
  683. Date: 22 Apr 1994 12:16:21 -0800
  684. Organization: (none)
  685.  
  686. Since sometimes you *have* to do a lot of sin/cos work I don't think these
  687. functions should be ignored. I'm toying with the idea of writing a fp
  688. library (probably mostly trig) that would calculate w.r.t. a determined
  689. precision. I remember writing programs on the VAX at school that seemed
  690. unbelievably slow at sin/cos. It turned out that I was getting far more
  691. precision than I needed. I rewrote the routines and got something like a
  692. 10x speed improvement. Often you don't need a lot of precision
  693. (particularly with graphics) so why do all of the work of calculating what
  694. you don't use? If there is interest in this I may pursue it further (of
  695. course I have to get a PM first! :-)
  696.  
  697.  
  698.     The fastest way to generate sin and cos is with a look-up table.  If
  699. you're doing statistical communications simulations, or doing a software
  700. modem, the table size deoesn't have to be very large for your error noise to
  701. be swamped by the input noise.  You can build the table from SANE or whatever
  702. else is handy when you need it.  If you need more precision, use of the above
  703. table in conjunction with the double-angle formula gives highly accurate
  704. results with minimal computation. We have used these techniques for years in
  705. simulations and in DSPs.  They are extremely computationally efficient.  In
  706. fact, if you write it for a PowerPC processor, you could pipeline the
  707. process, using both the integer and floating point units at the same time. 
  708. That sucker should scream with that type algorithm.
  709.  
  710.  
  711. G. Gordon Apple, PhD
  712. Advanced Communications Engineering, Inc.
  713. Redondo Beach, CA
  714.  
  715. +++++++++++++++++++++++++++
  716.  
  717. >From usenet@lowry.eche.ualberta.ca (Brian Lowry)
  718. Date: 24 Apr 1994 00:08:46 GMT
  719. Organization: Chem Eng - Univ of Alberta
  720.  
  721.   It really isn't so hard to code efficent sin/cos/sqrt routines.  There
  722. are complete reference books with excellent algorithms (for much more
  723. difficult functions than sin or cos).  If anyone wants simple sin, cos, and
  724. sqrt routines which are on the order of optimal (in C, no doubt assembly
  725. would be faster), then just send me e-mail.
  726.  
  727. --
  728.  
  729. Brian Lowry
  730.  
  731. ---------------------------
  732.  
  733. >From mkelly@cs.uoregon.edu (Michael A. Kelly)
  734. Subject: Determining if user is on a network
  735. Date: 25 Apr 1994 15:26:26 -0700
  736. Organization: High Risk Ventures
  737.  
  738.  
  739. Hey,
  740.  
  741. Is there any way to determine if a machine is on a local network?  I can
  742. find out if AppleTalk is on, but that doesn't tell me if the machine is
  743. part of a network.
  744.  
  745. Thanks,
  746.  
  747. Mike.
  748. -- 
  749. _____________________________________________________________________________
  750. Michael A. Kelly                                                President/CEO
  751. mkelly@cs.uoregon.edu                                      High Risk Ventures
  752. _____________________________________________________________________________
  753.  
  754. +++++++++++++++++++++++++++
  755.  
  756. >From mxmora@unix.sri.com (Matt Mora)
  757. Date: 26 Apr 1994 10:44:04 -0700
  758. Organization: SRI International, Menlo Park, CA
  759.  
  760. In article <2phg2i$9lb@majestix.cs.uoregon.edu> mkelly@cs.uoregon.edu (Michael A. Kelly) writes:
  761. >
  762. >Hey,
  763. >
  764. >Is there any way to determine if a machine is on a local network?  I can
  765. >find out if AppleTalk is on, but that doesn't tell me if the machine is
  766. >part of a network.
  767.  
  768.  
  769. Here you go. 
  770.  
  771. /*
  772.     Sample code to demonstrate use of the LAP Manager call to determine
  773.     the current connection type i.e LocalTalk, EtherTalk phase 1/2, or
  774.     TokenTalk phase 2.
  775.     Rich Kubota 
  776.     DTS
  777. */
  778.  
  779. #include <Types.h>
  780. #include <string.h>
  781.  
  782. #define LGetATalkInfo     0x09        /* Get AppleTalk info */
  783.  
  784. /* 'atlk' resource ID's of Apple supplied driver software. */
  785. #define    LTalk        0
  786. #define    ETalkPh1    2
  787. #define    TTalkPh2    5
  788. #define    ETalkPh2    10
  789. #define LAPMgrPtr             0xB18
  790. #define LAPMgrCall            2
  791.  
  792. #include "GetADEVType.h"
  793.  
  794. pascal long CallLAPMgr(short selector) 
  795. {
  796.     asm{
  797.         MOVE.W        selector,D0        ; move selector parameter into D0
  798.         MOVE.L        A2,-(A7)        ; store A2 on stack
  799.         MOVEA.L        LAPMgrPtr,A2    ; Set A2 to address of LAP Mgr.
  800.         JSR            LAPMgrCall(A2)    ; Call LAP Manager
  801.         MOVE.L        D1,0x0A(A6)        ; Place result onto stack
  802.         MOVE.L        (A7)+,A2        ; Restore A2
  803.         UNLK        A6                ; restore stack frame
  804.         MOVEA.L        (A7)+,A0        ; put return address into A0
  805.         ADDQ.W        #0x02,A7        ; clear off the parameter
  806.         JMP            (A0)            ; return to caller
  807.         RTS
  808.     }
  809. }
  810. void CheckNetType(char * resultStr)
  811. {
  812.     long    result;
  813.     char    adevType;
  814.     char    slot;
  815.     
  816.     //Debugger();
  817.     result = CallLAPMgr(LGetATalkInfo); 
  818.     adevType = result & 0x000000FF;    /* atlk resource id is return in LSB */
  819.     slot = result>>24;                 /* card slot returned in MSB */
  820.     
  821.     switch (adevType) {
  822.         case LTalk:
  823.                 strcpy(resultStr,"LocalTalk");
  824.                 break;
  825.         case ETalkPh1:
  826.                 strcpy(resultStr,"EtherTalk phase 1");
  827.                 break;
  828.         case ETalkPh2:
  829.                 strcpy(resultStr,"EtherTalk phase 2");
  830.                 break;
  831.         case TTalkPh2:
  832.                 strcpy(resultStr,"TokenTalk");
  833.                 break;
  834.         default:
  835.                 strcpy(resultStr,"Unrecognized connection");
  836.                 break;
  837.         }
  838.  
  839. }
  840.  
  841. Warning. I never could get this to work on all systems.
  842.  
  843. Xavier
  844.  
  845.  
  846.  
  847. -- 
  848. ___________________________________________________________
  849. Matthew Xavier Mora                       Matt_Mora@sri.com
  850. SRI International                       mxmora@unix.sri.com
  851. 333 Ravenswood Ave                    Menlo Park, CA. 94025
  852.  
  853. ---------------------------
  854.  
  855. >From neath@brazil.psych.purdue.edu (Ian Neath)
  856. Subject: Sample Think C AE Code
  857. Date: Wed, 20 Apr 1994 13:18:15 GMT
  858. Organization: Purdue University
  859.  
  860. As an amateur programmer trying to stay on the cutting edge
  861. of yesterday's technology, I'm trying to implement AE and
  862. custom AE into some apps.  I can't find much sample C code,
  863. though.  Any suggestions for locations (already tried
  864. sumex, etc.) greatly appreciated.  (We rarely get alt.sources.
  865. mac here)
  866.  
  867.  
  868. --
  869.       Ian Neath        | There are four kinds of people in this world:
  870. neath@psych.purdue.edu | cretins, fools, morons and lunatics - U. Eco
  871.  
  872. +++++++++++++++++++++++++++
  873.  
  874. >From Deirdre Maloy <Deeny3@aol.com>
  875. Date: Wed, 20 Apr 1994 18:24:07 GMT
  876. Organization: Metro Information Services, Raleigh NC
  877.  
  878. I remember that I found precious little about SENDING custom apple
  879. events. On the off chance this'll help, here's a sample sending code and
  880. receiving code (which go in two different apps). Despite the debug code,
  881. they do work -- one app sends another app the info about a file to
  882. launch, waits for an acknowledgement from the receiving app, then renames
  883. itself and quits. When the first app detects that the other app quit, it
  884. eats it. I had to do this for complicated reasons relating to auto-update
  885. version control experimentation. <g> All our applications are launched by
  886. the program we call "Itty" which is a faceless app that acts as a
  887. switchboard for apple events between our applications -- you can send an
  888. apple event to the Itty for an application that's not launched. It will
  889. then launch the app and forward the message when the app is ready to
  890. receive. This set of events is just designed for one app to tell the Itty
  891. to launch another app and when--though the when is controlled elsewhere.
  892.  
  893. _Deirdre
  894.  
  895. On receiving end:
  896. #include    "Launcher.h"
  897. #include    <Aliases.h>
  898.  
  899. extern    Boolean                highPriority;
  900. extern    launchRecord            myLaunchInfo[MAX_SUBLAUNCHES];        //    info on where
  901. app is located
  902. extern    short                currentLaunch;
  903. extern    Str255                myFile;                        //    name of current document
  904.  
  905.  
  906. pascal OSErr myHandleItty(AppleEvent *ittyEvent, AppleEvent *replyEvent,
  907. long refCon)
  908. {
  909.         OSErr        myErr;
  910.         AEDesc        myDesc;
  911.         long            actualSize;
  912.         DescType        actualType;
  913.         long            count;
  914.         AEDescList    myIttyList;
  915.         AEKeyword    myKeyword;
  916.         DescType        myType;
  917.         Str32        myString;
  918.     
  919.     highPriority = TRUE;
  920.     
  921.     myErr = AEGetParamPtr(ittyEvent, 'app ', 'fss ',
  922.                     &myType, (Ptr) &myLaunchInfo[currentLaunch].appName,
  923.                     (long) sizeof(FSSpec), &actualSize);
  924.     
  925.     myErr = HGetVol(myString,&myLaunchInfo[currentLaunch].appName.vRefNum,
  926.                     &myLaunchInfo[currentLaunch].appName.parID);
  927.  
  928.     myErr = AEGetParamPtr(ittyEvent, 'doc ', 's255',
  929.                     &myType, (Ptr) &myFile, (long) sizeof(Str255), &actualSize);
  930.                     
  931.     if (myErr != noErr)
  932.         myFile[0] = 0;
  933.     
  934.     CopyPString("\pHowdy",myString);
  935.                     
  936.     myErr = AEPutParamPtr(replyEvent, keyErrorString, typeChar,
  937. (Ptr)&myString[1], myString[0]);
  938.                     
  939.     SysBeep(3);
  940.     
  941.     return (noErr);
  942. }
  943.  
  944.  
  945. #include "Teeny.h"
  946. #include    <EPPC.h>
  947. #include    <AppleEvents.h>
  948.  
  949. extern    FSSpec                myAppLoc;        //    info on where doc to open is located
  950. extern    Str255                myDocPath;
  951. extern    ProcessSerialNumber    PSN;
  952. extern    Boolean                gQuit;
  953.  
  954. void    getIttyPSN(ProcessSerialNumber *ittyPSN, OSType ittySig);
  955. pascal Boolean MyIdleFunction(EventRecord *event,
  956.                     long *sleepTime, RgnHandle *mouseRgn);
  957.  
  958. void    sendIttyAE(void)
  959. {
  960.     //    Here's all the garbage you will need.
  961.  
  962.             OSType                ittyType = 'I???', ittyMsg = 'l8tr';
  963.             AEAddressDesc            ittyDesc;
  964.             AEDescList            myIttyList;
  965.             AEDesc                myApp, myDoc;
  966.             AppleEvent            myAppleEvent, myAEreply;
  967.             short                iErr;
  968.             ProcessSerialNumber    ittyPSN;
  969.             EventRecord            myEvent;
  970.  
  971.     //    create the address descriptor record.
  972.  
  973.         iErr = AECreateDesc(typeApplSignature, (Ptr)&ittyType,
  974. sizeof(ittyType), &ittyDesc);
  975.  
  976.     //    exit if there's an error
  977.  
  978.         if (iErr != noErr)
  979.             goto Sayonara;
  980.         
  981.     //    For the IttyBitty, the Apple Event TYPE should be 'I???',
  982.     //    which is also IttyBitty's signature. The Event ID should be one of
  983. the following:
  984.     //        'imed'    Launch this application IMMEDIATELY.
  985.     //        'delo'    Delete file.
  986.     //        'l8tr'    Launch this application when I quit.
  987.     //        (no other events defined)
  988.     //
  989.     //    in all cases, a parameter list is required
  990.     //        'app '    for application to launch (fsspec expected)
  991.     //        'doc '    for document to launch with app (Str255 expected)
  992.     //        'fss '        for any other fsspec
  993.     
  994.         iErr = AECreateAppleEvent(ittyType, ittyMsg, &ittyDesc,
  995. kAutoGenerateReturnID,
  996.                 kAnyTransactionID, &myAppleEvent);
  997.                 
  998.         if (iErr != noErr)
  999.             goto Sayonara;
  1000.         
  1001.         iErr = AEPutParamPtr(&myAppleEvent, 'app ', 'fss ', (Ptr) &myAppLoc,
  1002. (long) sizeof(FSSpec));
  1003.     
  1004.         if (myDocPath[0] > 2)
  1005.             iErr = AEPutParamPtr(&myAppleEvent, 'doc ', 's255', (Ptr) myDocPath,
  1006. (long) sizeof(Str255));
  1007.  
  1008.     //    We should be OK to send the apple event now.
  1009.     
  1010.         iErr = AESend(&myAppleEvent, &myAEreply, kAEWaitReply+kAECanInteract,
  1011.                     kAEHighPriority, 720, &MyIdleFunction, 0L);
  1012.     
  1013.         WaitNextEvent(0x2, &myEvent, 40L, 0);
  1014.                     
  1015.         if (iErr == noErr)    SysBeep(3);    //    to let user know AppleEvent was sent
  1016.         
  1017.         gQuit = TRUE;                    //    our task is done, the AppleEvent was sent
  1018.         
  1019. Sayonara:
  1020.         AEDisposeDesc(&ittyDesc);
  1021.         AEDisposeDesc(&myAppleEvent);
  1022.         AEDisposeDesc(&myAEreply);
  1023. }
  1024.  
  1025.  
  1026.  
  1027. // prototype your routine like this prior to calling it
  1028. // NOTE that it uses pascal calling conventions since it is called
  1029. // from the AESend routine
  1030. pascal Boolean MyIdleFunction(EventRecord *event,
  1031.                     long  *sleepTime, RgnHandle *mouseRgn);
  1032.  
  1033. // Application global variable to keep track of cursor rgn
  1034.  
  1035. RgnHandle gCursorRgn;
  1036.  
  1037. pascal Boolean MyIdleFunction(EventRecord *event,
  1038.                     long *sleepTime, RgnHandle *mouseRgn)
  1039. {
  1040.     char         hiByte;
  1041.     OSErr     myErr;
  1042.  
  1043.     switch ( event->what )
  1044.     {
  1045.         case updateEvt:
  1046.         case activateEvt:            // every idle function should handle
  1047.         case app4Evt:                // these kinds of events
  1048.             SetFrontProcess(&PSN);
  1049.             break;
  1050.         case nullEvent:
  1051.                                 // set the sleeptime and mouseRgn parameters
  1052.             *mouseRgn = gCursorRgn;
  1053.             *sleepTime = 10;        // use the correct value for your app
  1054.             SystemTask();            // the application's idle handling
  1055.             SystemTask();            // the application's idle handling
  1056.             SystemTask();            // the application's idle handling
  1057.             break;
  1058.     }
  1059.     return FALSE;
  1060. }
  1061.  
  1062.  
  1063.  
  1064. In article <CoK7MF.9Lq@mozo.cc.purdue.edu> Ian Neath,
  1065. neath@brazil.psych.purdue.edu writes:
  1066. >As an amateur programmer trying to stay on the cutting edge
  1067. >of yesterday's technology, I'm trying to implement AE and
  1068. >custom AE into some apps.  I can't find much sample C code,
  1069. >though.  Any suggestions for locations (already tried
  1070. >sumex, etc.) greatly appreciated.  (We rarely get alt.sources.
  1071. >mac here)
  1072. --
  1073. Deirdre Maloy, Metro Information Services, Raleigh NC
  1074. "My employer pays me for my opinions; you get them free."
  1075.  
  1076. +++++++++++++++++++++++++++
  1077.  
  1078. >From john40@aol.com (John40)
  1079. Date: 22 Apr 1994 19:25:02 -0400
  1080. Organization: America Online, Inc. (1-800-827-6364)
  1081.  
  1082. In article <CoK7MF.9Lq@mozo.cc.purdue.edu>, neath@brazil.psych.purdue.edu (Ian
  1083. Neath) writes:
  1084.  
  1085. >As an amateur programmer trying to stay on the cutting edge
  1086. >of yesterday's technology, I'm trying to implement AE and
  1087. >custom AE into some apps.  I can't find much sample C code,
  1088. >though.  Any suggestions for locations (already tried
  1089. >sumex, etc.) greatly appreciated.  (We rarely get alt.sources.
  1090. >mac here)
  1091.  
  1092. Get yourself a copy of UserLand Frontier's SDK 3.0.  It's packed with useful
  1093. Apple Events stuff.  The code is even free to use in your own programs
  1094. (no royalty, and its source code can even by distributed if you don't change it
  1095. - this is
  1096. according to their documentation).  You can get the SDK from BBSs such as
  1097. America Online
  1098. or by buying Frontier.
  1099.  
  1100. John Schlack
  1101.  
  1102.  
  1103. +++++++++++++++++++++++++++
  1104.  
  1105. >From eschen@molbio.cbs.umn.edu (Art Eschenlauer)
  1106. Date: Sun, 24 Apr 1994 18:04:22 GMT
  1107. Organization: University of Minnesota, Twin Cities
  1108.  
  1109. Today I noted in the MERIT Macintosh software archives at umich:
  1110.  
  1111. /mac/development/libraries/aebuilder1.1.cpt.hqx  (134K)
  1112. A ThinkC 5.0 kit to help construct and call Apple Events.
  1113. Very thorough and helpful. [Description theirs, not mine.]
  1114. --
  1115. eschen@molbio.cbs.umn.edu (Art Eschenlauer, 
  1116. U of M Agronomy and Plant Genetics Dept.)
  1117.  
  1118. ---------------------------
  1119.  
  1120. >From dacton@beak.com (Dan Acton)
  1121. Subject: drawing arrowheads
  1122. Date: 25 Apr 1994 08:36:10 -0600
  1123. Organization: Beak Consultants Ltd.
  1124.  
  1125. Has anyone out there figured out how to draw nice arrowheads on the ends of
  1126. lines similar to MacDraw, SuperPaint, Canvas, etc.?  I've written a routine
  1127. which uses QuickDraw arcs and some trigonometry and everyone says they look
  1128. terrible.
  1129. ********************************************
  1130.  Sent via BeakNet
  1131.  Beak Consultants Limited, Electronic Mail Network
  1132.    42 Arrow Road
  1133.    Guelph, Ontario, CANADA
  1134.    (519) 763-BEAK (voice)
  1135.    (519) 763-2378 (FAX)
  1136. ********************************************
  1137.  
  1138. +++++++++++++++++++++++++++
  1139.  
  1140. >From sw@network-analysis-ltd.co.uk (Sak Wathanasin)
  1141. Date: Tue, 26 Apr 94 00:12:12 GMT
  1142. Organization: Network Analysis Ltd
  1143.  
  1144.  
  1145. In article <1407844318.11694@beaknet1.beak.com> (comp.sys.mac.programmer), dacton@beak.com (Dan Acton) writes:
  1146. > Has anyone out there figured out how to draw nice arrowheads on the ends of
  1147. > lines similar to MacDraw, SuperPaint, Canvas, etc.?  I've written a routine
  1148. > which uses QuickDraw arcs and some trigonometry and everyone says they look
  1149. > terrible.
  1150.  
  1151. Oh well, I might as well get my code pulled apart. It's not
  1152. particularly efficient, but I only have to draw these occasionally. All
  1153. suggestions for improvement gratefully received. This has been pulled
  1154. from a MacApp prog; just assume that everything has been declared
  1155. appropriately. The consts were worked out using a desk calculator...
  1156.  
  1157. The method computes a QD poly, and is called whenever the start/end
  1158. points change. When I have to refresh the view, I call
  1159. PaintPoly(fArrowHead) after I draw the connecting line.
  1160.  
  1161. Set tabstops=4 for proper alignment.
  1162.  
  1163. pascal void
  1164. TEPConnection::CalcArrows    (void)
  1165. {
  1166.     const extended    kDeg2Rad     = 0.01745329252;        // for converting degrees to radians
  1167.     const extended    kArrowLength = 10.0;                // length of arrowhead
  1168.     const extended    kArrowAngle  = kDeg2Rad * 30.0;        // angle arrow makes with line
  1169.     short            angle;                                // angle between connecting line & vertical axis
  1170.     Rect            r;
  1171.                                                         // bounding box of agent
  1172.     Point            apex          = fEndPt;                // point of the arrow
  1173.     Point            pt2, pt3;                            // corners of the arrow
  1174.     
  1175.     r.left    = fStartPt.h - 10;
  1176.     r.top    = fStartPt.v - 10;
  1177.     r.right    = fStartPt.h + 10;
  1178.     r.bottom= fStartPt.v + 10;                            // concoct a square around the start pt
  1179.     PtToAngle(&r, apex, &angle);                        // calc angle of connecting line
  1180.     extended    rangle = (extended)(90-angle) * kDeg2Rad;
  1181.                                                         // the angle in radians                                                        // the angle in radians
  1182.     extended    temp    = rangle - kArrowAngle;
  1183.     pt2.h    = (short)((extended)apex.h - (kArrowLength * cos(temp)));
  1184.     pt2.v    = (short)((extended)apex.v + (kArrowLength * sin(temp)));
  1185.     temp     = rangle + kArrowAngle;
  1186.     pt3.h    = (short)((extended)apex.h - (kArrowLength * cos(temp)));
  1187.     pt3.v    = (short)((extended)apex.v + (kArrowLength * sin(temp)));
  1188.     
  1189.     if (fArrowPoly != NULL) {
  1190.         KillPoly(fArrowPoly);                            // get rid of prev arrow
  1191.         fArrowPoly = NULL;
  1192.     }
  1193.     PolyHandle    arrowPoly = OpenPoly();
  1194.     FailNULL(arrowPoly);
  1195.     MoveTo(apex.h, apex.v);
  1196.     LineTo(pt2.h, pt2.v);
  1197.     LineTo(pt3.h, pt3.v);
  1198.     LineTo(apex.h, apex.v);
  1199.     ClosePoly();
  1200.     fArrowPoly    = arrowPoly;    
  1201.  
  1202.     // reset the bounding box
  1203.     // ... some code to compute the bounding box, which you probably don't need
  1204. }
  1205.  
  1206. Sak Wathanasin
  1207. Network Analysis Limited
  1208. 178 Wainbody Ave South, Coventry CV3 6BX, UK
  1209.  
  1210. Internet: sw@network-analysis-ltd.co.uk 
  1211. uucp:     ...!uknet!nan!sw                       AppleLink: NAN.LTD
  1212. Phone: (+44) 203 419996 Mobile:(+44) 850 587411  Fax: (+44) 203 690690
  1213.  
  1214. ---------------------------
  1215.  
  1216. >From jadams@eng.umd.edu (Josh Adams)
  1217. Subject: writing an INIT... a few questions
  1218. Date: 22 Apr 1994 16:14:32 GMT
  1219. Organization: Project GLUE, University of Maryland, College Park
  1220.  
  1221. Hi,
  1222. I am a somewhat new Mac programmer. I have written some apps, but now I want
  1223. to write an INIT (I think). I was wondering a few things:
  1224. 1) Is there some info somewhere that documents how to do this and ant
  1225. background info I should have about things like memory and registers
  1226. and such?
  1227. 2) If I want to patch a trap for all applications, but I want to have a
  1228. window constantly displaying stuff, should I have an init to patch the 
  1229. trap(s) and then have it launch an app at startup, then send info from
  1230. the patched trap to my app with Apple Events? Would there be a better 
  1231. way? I couldn't imagine that it would be good to have the init make
  1232. a window...
  1233. 3) What does it mean to detach a resource? Would this affect me? 
  1234. 4) What registers do I have to care about?
  1235. 5) Is there a way to access the small black line at the bottom of the 
  1236. menu bar? Like if I drew something there, the menu would just erase
  1237. over it, right? Is there a way to change the line to be more than one
  1238. color? (Just wondering... I probably won't need to, but it is interesting
  1239. to know.
  1240.  
  1241. Thanks for all replies and info,
  1242. Stu
  1243.  
  1244.  
  1245. +++++++++++++++++++++++++++
  1246.  
  1247. >From Aaron Wohl <aw0g+@andrew.cmu.edu>
  1248. Date: Mon, 25 Apr 1994 07:18:46 -0400
  1249. Organization: Systems Group 97, Carnegie Mellon, Pittsburgh, PA
  1250.  
  1251. For the source code to three inits look in host akutaktak.andrew.cmu.edu
  1252. [128.2.35.1] /aw0g/*.hqx.
  1253.  
  1254. Excerpts from netnews.comp.sys.mac.programmer: 22-Apr-94 writing an
  1255. INIT... a few qu.. Josh Adams@eng.umd.edu (1094)
  1256.  
  1257. > 1) Is there some info somewhere that documents how to do this and ant
  1258. > background info I should have about things like memory and registers
  1259. > and such?
  1260.  
  1261.  
  1262. Not that I know of.   I guess I should write a how to write an
  1263. INIT/DRVR/CDEV faq...
  1264.  
  1265. Excerpts from netnews.comp.sys.mac.programmer: 22-Apr-94 writing an
  1266. INIT... a few qu.. Josh Adams@eng.umd.edu (1094)
  1267.  
  1268. > 2) If I want to patch a trap for all applications, but I want to have a
  1269. > window constantly displaying stuff,
  1270.  
  1271. The patch code needs to live in the system heap (otherwise multifinder
  1272. will swap the patch out when it switches applications).  The patch
  1273. should probably post it's information to a device driver.  The
  1274. application should read it from the driver.   I don't know enough about
  1275. apple events to know what problems there would be in using them.  I
  1276. suspect that there would be difficulties in getting the port for apple
  1277. events to not be closed when the applicaiton that was running when it
  1278. was opened quit.
  1279.  
  1280. Excerpts from netnews.comp.sys.mac.programmer: 22-Apr-94 writing an
  1281. INIT... a few qu.. Josh Adams@eng.umd.edu (1094)
  1282.  
  1283. > 3) What does it mean to detach a resource? Would this affect me? 
  1284.  
  1285.  
  1286. A code resource (the code for an INIT) is still attached to the resource
  1287. map for the init file.   If you don't detach it (with DetachResource)
  1288. the code block will be reused when the mac os cleans up after your init
  1289. starts and it goes on to the next init.  Rather than detach the init
  1290. code I prefer to have the init install anouther code resource.  That way
  1291. the installation part of the init code is freeed as it should be.
  1292.  
  1293. Excerpts from netnews.comp.sys.mac.programmer: 22-Apr-94 writing an
  1294. INIT... a few qu.. Josh Adams@eng.umd.edu (1094)
  1295.  
  1296. > 4) What registers do I have to care about?
  1297.  
  1298.  
  1299. For an init in general you don't have to worry about it.  Except if you
  1300. are using think c (which I recommend) you need to set up the A4
  1301. register.   See the init code in the softkiss driver for a good example
  1302. of dealing with this. 
  1303.  
  1304. ---------------------------
  1305.  
  1306. End of C.S.M.P. Digest
  1307. **********************
  1308.  
  1309.  
  1310.  
  1311.  
  1312.